import { Controller, Get, Post, Body, UseGuards ,Request, UseInterceptors, ClassSerializerInterceptor} from '@nestjs/common';
import { UsersService } from './users.service';
import { CreateUserDto } from './dto/create-user.dto';
import { RolesGuard } from'../guards/roles/roles.guard'
import { Roles,Role } from 'src/guards/roles/roles';
import { AuthGuard } from '@nestjs/passport';
import { resolve } from 'path';
import { ApiTags } from '@nestjs/swagger';
import { User } from './entities/user.entity';
import { DeepPartial } from 'typeorm';

@ApiTags('users')
@Controller('users')
@UseGuards(RolesGuard)
export class UsersController {
  constructor(private readonly usersService: UsersService) {}
  
  @UseInterceptors(ClassSerializerInterceptor)
  @Post('register')
  async register(@Body() createUserDto: CreateUserDto):Promise<User>{
    let userInfo = await this.usersService.register(createUserDto) 
    return new User({
      ...userInfo
    })
  }
    
  @Post('login')
  login(@Body() createUserDto: CreateUserDto){
    return this.usersService.login(createUserDto)
  }

  @Post('test')
  //@UseGuards(AuthGuard('jwt'))
  //@Roles(Role.Admin)
  test(@Body() req:any) {
    //const user = req.user;
    return 's'
  }
  
  @Get()
  findAll() {
    return this.usersService.findAll();
  }  

}


